package org.springblade.mach;

import org.springblade.mach.entity.DrawingInfo;
import org.springblade.mach.entity.DrawingInfoTreeNode;
import org.springblade.mach.vo.DrawingInfoVO;

import java.util.List;

/**
 * @author LY
 * @version 1.0
 * @date 2021/4/13 15:30
 */
public class DrawingNodeMerger {
	public DrawingNodeMerger(){}
	public static <T extends DrawingInfoNodeInteface<T>> List<T> merge(List<T> items) {
		DrawingInfoNodeManager<T> forestNodeManager = new DrawingInfoNodeManager(items);
		items.forEach((forestNode) -> {
			if (forestNode.getParentId() != 0L) {
				DrawingInfoNodeInteface node = forestNodeManager.getTreeNodeAt(forestNode.getParentId());
				if (node != null) {
					node.getChildren().add(forestNode);
				} else {
					forestNodeManager.addParentId(forestNode.getInfoId());
				}
			}

		});
		return forestNodeManager.getRoot();
	}
}
